<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<%@include file="/common/taglibs.jsp"%>
<%@include file="/common/meta.jsp"%>
<script type="text/javascript" src="<c:url value='/common/js/ajaxfileupload.js'/>" charset="utf-8"></script>
<title>增加字典</title>
</head>
<body>
	
	<form id="dicForm" action="<c:url value='/pf/dictionary/aDictionary'/>" method="post" autocomplete="off">
		<input type="hidden" name="dicParentId" value="${dic.id }"/>
		<input type="hidden" id="filePath" name="filePath" />
		<table class="add_form">
			<tr>
				<td align="right" width="35%">
					<label>字典名称:</label>
				</td>
				<td width="70%">
					<input name="dicName" class="add_input" required/>
				</td>
			</tr>
			<tr>
				<td align="right">
					<label>父字典名称:</label>
				</td>
				<td>
					<c:out value="${dic.dicName }"/>
				</td>
			</tr>
			<tr>
				<td align="right">
					<label>是否有效:</label>
				</td>
				<td>
					<input type="radio" checked="checked" name="dicIsvalid" value="1" />有效
					<input type="radio" name="dicIsvalid" value="0"/>无效
				</td>
			</tr>
			<tr>
				<td align="right">
					<label>排序值:</label>
				</td>
				<td>
					<input name="dicOrderNo" class="add_input" required/>
				</td>
			</tr>
			<tr>
				<td align="right">
					<label>备注:</label>
				</td>
				<td>
					<textarea rows="" cols=""  name="dicRemark" class="add_textarea"></textarea>
				</td>
			</tr>
			<tr>
			    <td align="right">地图位置图片 ：</td>
			    <td><input type="file" name="file" id="file" style="width: 188px;" onchange="ajaxUploadFile()"/>&nbsp;&nbsp;<input type='button' style="display:none;" title='删除' value='X' id="deleteFile" onclick="delFile();"/></td>
			</tr>
			
			<tr>
				<td colspan="2" align="center">
					<input id="submit" type="button" value="保存"/>
				</td>
			</tr>
		</table>
	</form>
	
	<script type="text/javascript">
		$(function() {
			var ajax_option = {
				success:function(data, status, xhf) {
					if("success" == status) {
						//关闭窗口，刷新父页面
						parent.closeAndRefresh();
					} else {
						art.dialog.alert(data.msg);
					}
				}
			};
			$("#dicForm").ajaxForm();
			$("#submit").click(function() {
				if($("#dicForm").valid()) {
					$("#dicForm").ajaxSubmit(ajax_option);
				}
			});
		});
		
		
		function ajaxUploadFile() {
			 $.ajaxFileUpload ({
		             url: "<%=request.getContextPath() %>/pf/dictionary/ajaxUploadFile", //用于文件上传的服务器端请求地址
		             secureuri: false, //是否需要安全协议，一般设置为false
		             fileElementId: 'file', //文件上传域的ID
		             dataType: 'json', //返回值类型 一般设置为json
		             success: function (re) { //服务器成功响应处理函数
			             alert(re);
	             		if (re.status) {
	             		//alert(re.value);
	                	$("#filePath").val(re.value);
	                	$("#deleteFile").css("display", "");
		                } else {
		                	alert(re.msg);
		                }
		             },
		             error: function (data, status, e)//服务器响应失败处理函数
		             {
		                 alert(e);
		             }
		         }
		     )
		     return false;
		}
		
		function delFile() {
			$("#deleteFile").css("display", "none");
		    $("#file").val("");
		    $("#filePath").val("");
		}
	</script>
</body>
</html>